package ru.st.selenium.applogic3;

import org.openqa.selenium.WebDriver;
import ru.st.selenium.applogic.ApplicationManager1;
import ru.st.selenium.applogic.TelerikHelper;
import ru.st.selenium.util.Browser;
import ru.st.selenium.util.PropertyLoader;
import ru.st.selenium.webdriver.WebDriverFactory;

public class ApplicationManager3 implements ApplicationManager1 {

	private TelerikHelper telHelper;
	private WebDriver driver;
	private String baseUrl;

	public ApplicationManager3() {

		baseUrl = PropertyLoader.loadProperty("telerik.url");
		String gridHubUrl = PropertyLoader.loadProperty("grid2.hub");

		Browser browser = new Browser();
		browser.setName(PropertyLoader.loadProperty("browser.name"));
		browser.setVersion(PropertyLoader.loadProperty("browser.version"));
		browser.setPlatform(PropertyLoader.loadProperty("browser.platform"));

		String username = "";
		String password = "";

		driver = WebDriverFactory.getInstance(gridHubUrl, browser, username,
				password);
		// driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

		telHelper = new TelerikHelper3(this);

		getTelerikHelper().openMainPage();
	}

	@Override
	public TelerikHelper getTelerikHelper() {
		return telHelper;
	}

	protected WebDriver getWebDriver() {
		return driver;
	}

	protected String getBaseUrl() {
		return baseUrl;
	}

	@Override
	public void stop() {
		if (driver != null) {
			driver.quit();
		}
	}
}
